﻿using System;
using fastCSharp;

namespace diantou.web.onlineJudge
{
    /// <summary>
    /// 问题题解
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPool = true, IsPage = false)]
    partial class problemSolution : problemView<problemSolution>
    {
        /// <summary>
        /// 问题题解
        /// </summary>
        /// <param name="problemId"></param>
        /// <returns></returns>
        protected override bool loadView(int problemId)
        {
            if (currentUser != null)
            {
                if (problemId == 0)
                {
                    checkSearchEngine(diantou.dataModel.path.pub.Default.OnlineJudgeAllProblemPath, webConfig.NotFound404);
                    return false;
                }
                if ((problem = diantou.dataAccess.clientCache.Problem[problemId]) != null)
                {
                    if (problem.Solution.Length != 0)
                    {
                        if (currentUser.IsOnlineJudgeEditor(problem) || userProblem.IsAccepted) return true;
                        if (problem.ShowType == dataModel.problem.showType.Show)
                        {
                            if (!userProblem.IsSolution)
                            {
                                problem = problem.Clone();
                                problem.Solution = string.Empty;
                            }
                            return true;
                        }
                    }
                    problem = null;
                }
            }
            AjaxResponse(webConfig.NotFound404);
            return false;
        }
    }
}
